//
//  FixPDViewController.swift
//  GZMarathon
//
//  Created by apple on 2021/11/11.
//

import UIKit
import SVProgressHUD
class FixPDViewController: UIViewController ,UITextFieldDelegate{

    @IBOutlet weak var subBt: UIButton!
    @IBOutlet weak var bottomTF: UITextField!
    @IBOutlet weak var centerTF: UITextField!
    @IBOutlet weak var topTF: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "修改密码"
        bottomTF.clearButtonMode = .always
        centerTF.clearButtonMode = .always
        topTF.clearButtonMode = .always
        
        bottomTF.delegate = self
        centerTF.delegate = self
        topTF.delegate = self
        // Do any additional setup after loading the view.
  

    }

    
    @IBAction func subClick(_ sender: UIButton) {
        
        if topTF.text?.count == 0 {
            SVProgressHUD.showError(withStatus: "请输入原始密码")
            return
        }
        
        if centerTF.text?.count == 0 {
            SVProgressHUD.showError(withStatus: "请输入新密码")
            return
        }
        
        if bottomTF.text?.count == 0 {
            SVProgressHUD.showError(withStatus: "请输入确认密码")
            return
        }
        
        if centerTF.text! != bottomTF.text!{
            SVProgressHUD.showError(withStatus: "两次密码输入不一致")
            return
        }
        
        ApiLoadingProvider.request(EBAPI.adminPwd(old_pwd: topTF.text!, new_pwd: centerTF.text!, confirm_pwd: bottomTF.text!), model: BaseModel.self) { model, isSuccess in
        
            guard let msg = model?.message else{
                SVProgressHUD.showError(withStatus: "修改失败, 请稍后再试")
                return
            }
            
            if msg == "成功"{
                SVProgressHUD.showSuccess(withStatus: "修改成功")
                self.navigationController?.popViewController(animated: true)
            }else{
                SVProgressHUD.showError(withStatus: msg)
            }
            
        }
        
    }
    func textFieldDidChangeSelection(_ textField: UITextField) {
        if((bottomTF.text?.count != 0) && (centerTF.text?.count != 0) && (topTF.text?.count != 0)){
            subBt.backgroundColor = UIColor("#2E4BF4")
            subBt.isUserInteractionEnabled = true
        }else{
            subBt.isUserInteractionEnabled = false
            subBt.backgroundColor = UIColor("#C1C9FC")

        }
    }

}
